<?php 

//控制基类
class Controller extends Smarty
{
    //构造方法 smarty 初始化
    public function __construct()
    {
        // Smarty 配置
        $this->setTemplateDir('./views') //模版
               ->setCompileDir('./runtime/views_c') //编译
               ->setConfigDir('./configs') // 配置
               ->setCacheDir('./runtime/caches'); //缓存

        // 配置 模版变量定界符 
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = RIGHT_D;
        // 配置 缓存
        $this->caching = CACHING;
        // 配置 缓存时间
        $this->cache_lifetime = CACHE_LIFETIME;//开启缓存30s
    }

    //跳转
    public function redirect($message, $url=null)
    {
        echo "<script>alert('{$message}')</script>";
        if (empty($url)) {
            //回到来之前的页面
            echo "<script>history.back()</script>";
        } else {
            // 指定页面跳转
            echo "<script>location.href='{$url}'</script>";
        }
    }

    //处理那些 调用时不存在的方法
    public function __call($fun, $params)
    {
        header("HTTP/1.0 404 not found");//非IE
        header("Status:404 not found");//IE兼容
        echo "<h1>404 NOT FOUND..</h1>";
        exit;
    }

}
